import router from './router'
import { getToken, setToken } from '@/utils/auth'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
setToken('5688948')
NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/login'] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
  NProgress.start()
  if (getToken()) {
    next()
    NProgress.done()
  } else {
    if (whiteList.includes(to.path)) {
      next()
      NProgress.done()
    } else {
      next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
      NProgress.done()
    }
  }
})
